package com.app.newiptv.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.Nullable;

public class MySitcomIndexOpenHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "sitcom_index.db";//数据库文件名
    private static SQLiteDatabase WRITE_INSTANCE;
    private static SQLiteDatabase READ_INSTANCE;
    private Context mContext;
    private static MySitcomIndexOpenHelper instance = null;
    public MySitcomIndexOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MySitcomIndexOpenHelper(Context context) {
        this(context, DB_NAME, null, 1);
        this.mContext=context;
    }
    public static MySitcomIndexOpenHelper getInstance(Context context) {
        if (instance == null) {
            instance = new MySitcomIndexOpenHelper(context);
        }
        return instance;
    }
    public SQLiteDatabase getWriteInstance() {
        if (WRITE_INSTANCE == null) {
            WRITE_INSTANCE = new MySitcomIndexOpenHelper(mContext).getWritableDatabase();
        }
        return WRITE_INSTANCE;
    }

    public SQLiteDatabase getReadInstance() {
        if (READ_INSTANCE == null) {
            READ_INSTANCE = new MySitcomIndexOpenHelper(mContext).getReadableDatabase();
        }
        return READ_INSTANCE;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 0为收藏 1为观看记录
        String create_sql = "create table if not exists SitcomIndex(id integer primary key  autoincrement, name varchar(20) not null, sitcom_index text)";
        db.execSQL(create_sql);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
